import { Ref, ref, watchEffect } from 'vue'
import { NumData } from '../types'

/**
 * 各年级未测分布
 */
export function useGradesNotTested({
  numData,
}: {
  numData: Ref<NumData | null>
}) {
  const gradeNoAxisData = ref<string[]>([])
  const gradeNoSeriesData = ref<number[]>([])

  watchEffect(() => {
    if (!Array.isArray(numData.value?.allGradeNoTestNum)) {
      return
    }
    gradeNoAxisData.value = []
    gradeNoSeriesData.value = []

    const allGradeNoTestNum =
      numData.value?.allGradeNoTestNum.sort(
        (a, b) => Number(a.code) - Number(b.code)
      ) || []

    allGradeNoTestNum.map((item) => {
      gradeNoAxisData.value.push(item.code)
      gradeNoSeriesData.value.push(item.num)
    })
  })
  return {
    gradeNoAxisData,
    gradeNoSeriesData,
  }
}
